using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ExcellOnServices.Models.Mapping
{
    public class OrderItemMap : EntityTypeConfiguration<OrderItem>
    {
        public OrderItemMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            // Table & Column Mappings
            this.ToTable("OrderItems");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.ServicePrice).HasColumnName("ServicePrice");
            this.Property(t => t.Product_Id).HasColumnName("Product_Id");
            this.Property(t => t.Service_Id).HasColumnName("Service_Id");
            this.Property(t => t.Order_Id).HasColumnName("Order_Id");

            // Relationships
            this.HasRequired(t => t.Order)
                .WithMany(t => t.OrderItems)
                .HasForeignKey(d => d.Order_Id);
            this.HasRequired(t => t.Product)
                .WithMany(t => t.OrderItems)
                .HasForeignKey(d => d.Product_Id);
            this.HasRequired(t => t.Service)
                .WithMany(t => t.OrderItems)
                .HasForeignKey(d => d.Service_Id);

        }
    }
}
